package com.cqjtu.eecs.utils.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.util.ListUtils;
import com.cqjtu.eecs.entity.dto.TeacherDto;
import com.cqjtu.eecs.service.ITeacherService;
import lombok.Data;
import org.apache.commons.collections4.SetUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @description: 教师信息excel读取监听器
 * @author: 徐文升
 * @create: 2022-03-08 17:42
 **/

@Data
public class TeacherListener implements ReadListener<TeacherDto> {

    private ITeacherService teacherService;

    private List<TeacherDto> teacherDtoList = ListUtils.newArrayList();

    public TeacherListener(ITeacherService teacherService) {
        this.teacherService = teacherService;
    }

    @Override
    public void invoke(TeacherDto teacherDto, AnalysisContext analysisContext) {
        teacherDtoList.add(teacherDto);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        teacherService.importTeacherExcelInfo(teacherDtoList);
    }
}
